import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

// 注册一个全局自定义指令 `v-allow`
Vue.directive('allow', {
  inserted: function(el, binding) {
    // 从vuex中取出points,
    const points = store.state.user.userInfo.roles.points
    console.log('binding.value', binding.value)
    // 如果points有binding.value则显示
    if (!points.includes(binding.value)) {
      el.style.display = 'none'
    }
  }
})

// 全局注册组件
import MyUI from './components'
Vue.use(MyUI)
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */

// set ElementUI lang to EN
// 控制语言
Vue.use(ElementUI)
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

// process.env是node.js提供的环境变量,可以在环境直接使用
// 会根据程序执行的环境自动加载不同的配置文件

if (process.env.NODE_ENV === 'development') {
  console.log('代表开发环境')
} else {
  console.log('代表生产环境')
}

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: (h) => h(App)
})
